def Prostoe(n):
  if n <= 1:
    return False
  for i in range(2, int(n**0.5) + 1):
    if n % i == 0:
      return False
  return True


def Naiti_Bolshoe_Prostoe(number):
  if number < 1000 or number > 9999:
    return 0

  digits = str(number)
  Bolshoe_Prostoe = 0

  for i in range(len(digits)):
    for j in range(i + 1, len(digits) + 1):
      num = int(digits[i:j])
      if Prostoe(num) and num > Bolshoe_Prostoe:
        Bolshoe_Prostoe = num

  return Bolshoe_Prostoe


number = int(input())
print(Naiti_Bolshoe_Prostoe(number))
